/// @TOPDESC: this acceptor does not have its own module,
///           so no need to prefix `XM_`

#ifndef XM_ACCEPTOR_HH
#define XM_ACCEPTOR_HH

#include <functional>
// this include
#include "XM_noncopyable.hh"
#include "XM_Socket.hh"
#include "XM_Channel.hh"
#include "pch.hh"

XM_NAMESPACE_BEGIN

struct EvLoop; // TODO: rename
struct InetAddr; // TODO: rename

struct Acceptor : private XM_noncopyable
{
    using NewConnectionCallback = std::function<void(int sockfd, const InetAddr&)>;
    /// @desc: init funcs
    Acceptor(EvLoop* ev_loop, const InetAddr& listenAddr, bool reusePort);

    ~Acceptor();
    /// @desc: public funcs
    void setNewConnectionCallback(const NewConnectionCallback& cb)
    {
        newConnCallback__ = cb;
    }
    // TODO: rename
    bool isListening() const { return listening__; } // is listening
    // TODO: rename
    void doListen();

private:
    void fixRead(); // TODO: rename
    // TODO: private field rename
    EvLoop* ev_loop__;
    Socket acceptSocket__;
    Channel acceptChannel__;
    NewConnectionCallback newConnCallback__;
    bool listening__;
};

XM_NAMESPACE_END

#endif // header file protect